package models

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

type Company struct {
	CompanyId int64 `orm:"pk;auto;column(company_id)"`
	CompanyName string `orm:"size(100);column(company_name)"`
	CreateDate time.Time `orm:"type(date);column(create_date)"`
	UpdateDate time.Time `orm:"type(date);column(update_date)"`
	Delete int `orm:"type(int);column(delete)"`
	UserId int64 `orm:"type(int);column(user_id)"`
}

func (c *Company) TableName()string  {
	return "t_company"
}

func AddCompany(c Company) bool {
	newOrm := orm.NewOrm()
	_, err := newOrm.Raw("insert into(company_name,create_date,update_date,delete,user_id) values(?,?,?,?,?)",c.CompanyName,c.CreateDate,c.UpdateDate,c.Delete,c.UserId).Exec()
	if err!=nil{
		panic(err)
	}
	return true
}

func QueryCompanyListByLikeCompanyName(companyName string) []Company{
	newOrm := orm.NewOrm()
	var companys [] Company
	_, err := newOrm.Raw("select * from t_company where company_name like '%"+ companyName+"%'").QueryRows(&companys)
	if err!=nil{
		panic(err)
	}
	return companys
}


